<template>
  <div class="search">
    <f-form ref="form" :action="api.msgType" :form-key="this.formItem.msgTypeId" :file-ids="fileIds">
      <f-form-item label="类型名称"  name="typeName"    :value="formItem.typeName" />
      <f-form-item label="类型编码"  name="typeCode"    :value="formItem.typeCode" />
      <f-form-item label="类型图标" type="upload" name="typeIcon"    :value="formItem.typeIcon" @uploadSuccess="typeIconUploadSuccess" />
      <f-form-item label="排序号" type="number" name="sortOrder" dataType="number"   :value="formItem.sortOrder" />
    </f-form>
  </div>
</template>
<script>
  import api from './js/api'
  export default {
    name: 'typeForm',
    props: {},
    data() {
      return {
        api:api,
        isAdd: true,//是否是添加模式
        loaded: false,//是否加载完成
        fileIds: [],//上传文件ID
        formItem: this.getFormItem()
      }
    },
    methods: {
      getFormItem() {
        return {
          msgTypeId: '',
          typeName: '',
          typeCode: '',
          typeIcon: '',
          sortOrder: ''
        }
      },
      //表单赋值
      setData(data) {
        this.$refs.form.resetFields()
        this.formItem = this.getFormItem()
        if (data && data.msgTypeId) {
          this.formItem = data
          this.isAdd = false
          this.loaded = true
        } else {
          this.loaded = true
        }
      },
      //类型图标上传回调
      typeIconUploadSuccess(fileUrl, files, fileIds, removeIds) {
        this.fileIds = fileIds
      },
      //提交表单
      handleSubmit(callback) {
        this.$refs.form.submit({  }, callback)
      }
    },
    created() {
    },
    components: {}
  }
</script>

<style scoped lang="less" rel="stylesheet/less">

</style>
